<template>
  <view class="page-container">
    <view class="bg1 w-full absolute top-0 ">
    </view>
    <u-navbar :fixed="false" leftIconSize="0" bgColor="transparent">
      <template #center>
        <view :class="['text-ff']">
          低空科技-执照考题宝典
        </view>
      </template>
    </u-navbar>

    <scroll-view scroll-y="true" class="page-body py-20 ">
      <view class="px-24">
        <u-swiper :list="list1" keyName="img" indicator indicatorMode="line" circular autoplay :interval="6000"
          radius="5" height="140"></u-swiper>
        <view class="gride2 box-shadows p-20 my-24 rounded-24 bg-ff">
          <view class="gride2-item1 rounded-20 flex flex-col justify-center items-center py-16 text-ff"
           @click="toPractice(1)">
            <view class="mb-6 font-32 font-bold">顺序练习</view>
            <view class="font-24 mb-6">真题演练</view>
            <image class="w-82 h-72" src="/static/images/A11.png" />
          </view>
          <view class="gride2-item2 rounded-20 flex flex-col justify-center items-center py-16 text-ff"
          @click="toPractice(6)">
            <view class="mb-6 font-32 font-bold">模拟考试</view>
            <view class="font-24 mb-6">100%仿真试题</view>
            <image class="w-82 h-72" src="/static/images/A15.png" />
          </view>
        </view>
        <view class="bg-ff pt-24 pb-32 px-32 flex items-center justify-between box-shadows rounded-t-l-20 rounded-t-r-20">
          <view class="flex flex-col justify-center items-center" @click="toPractice(2)">
            <image src="/static/images/A01.png" class="icon-60"></image>
            <view class="font-24 text-64 mt-10">随机练习</view>
          </view>
          <view class="flex flex-col justify-center items-center"  @click="toPractice(3)">
            <image src="/static/images/A02.png" class="icon-60"></image>
            <view class="font-24 text-64 mt-10">我的收藏</view>
          </view>
          <view class="flex flex-col justify-center items-center"  @click="toPractice(4)">
            <image src="/static/images/A03.png" class="icon-60"></image>
            <view class="font-24 text-64 mt-10">我的错题</view>
          </view>
          <view class="flex flex-col justify-center items-center"  @click="toPractice(5)">
            <image src="/static/images/A10.png" class="icon-60"></image>
            <view class="font-24 text-64 mt-10">答题记录</view>
          </view>
        </view>
        <view class=" relative top10" @click="gosignup">
          <image :src="utils.imgFormat('/profile/image/report.png')" class="h-162 w-full"></image>
        </view>
        <view class="mt-30 bg-ff px-20 py-32 rounded-20">
          <view class="flex justify-between items-center" @click="toPractice(7)">
            <view class="flex items-center">
              <image class="w-32 h-28 mr-24" src="/static/images/A12.png" />
              <view>教员试题</view>
            </view>
            <image class="icon-28" src="/static/images/A14.png" />
          </view>
          <view class="line my-24"></view>
          <view class="flex justify-between items-center " @click="toPractice(8)">
            <view class="flex items-center">
              <image class="w-32 h-28 mr-24" src="/static/images/A13.png" />
              <view>新闻内容</view>
            </view>
            <image class="icon-28" src="/static/images/A14.png" />
          </view>
        </view>
      </view>
    </scroll-view>
  </view>

</template>

<script setup>
import { ref} from 'vue'
import {onLoad,onShareAppMessage} from "@dcloudio/uni-app"
import utils from '@/utils/utils.js'
import  {system} from '@/api'
import {useLogin,checkAudit} from '@/common/useLogin.js'
import useUserStore from '@/store/user.js'
const useStore = useUserStore()
const list1 = ref([
  {
    img: utils.imgFormat('/profile/picture/2025/06/19/c5ca41ef-88a7-441d-9b63-8145b3c0baf9.png'),
    title: '轮播图0',
  },
  {
    img: utils.imgFormat('/profile/upload/2025/03/05/99229f0e-806f-4933-858e-46e790038246.png'),
    title: '轮播图1',
  },
  {
    img: utils.imgFormat('/profile/upload/2025/03/05/fce4edc3-21a3-4c65-8015-11b8fcb6d8d4.png'),
    title: '轮播图2',
  }
])


onLoad(async (options) => {
  getBanner()
})
//获取banner
const getBanner = () => {
  system.getBanner({limit: 5,type: 1}).then(res => {
    console.log('banner',res)
    if(res.code === 0){
      list1.value = res.data.map(item => {
        return {
          img: utils.imgFormat(item.imgUrl),
          title: item.title
        }
      })
      console.log('list1',list1.value)
    }
  })
}
//去报名
const gosignup = () => {
  if(!useStore.userInfo.avatarUrl){
    uni.showToast({title: '请先登录',icon: 'none'})
    setTimeout(() => {
      uni.reLaunch({
        url: '/pages/welcome/index'
      })
    }, 1000)
    return
  }
  uni.navigateTo({
    url: '/pages/registerInformation/index'
  })
}

//去练习
const toPractice = (type) => {
  if(!useStore.userInfo.avatarUrl){
    uni.showToast({title: '请先登录',icon: 'none'})
    setTimeout(() => {
      uni.reLaunch({
        url: '/pages/welcome/index'
      })
    }, 1000)
    return
  }
  useLogin((isLogin) => {
    console.log('是否登录',isLogin)
    if(type === 6){
      return uni.navigateTo({
        url: '/pages/index/SimulatedExam/index'
        })
    }
    if(type === 7){
      return uni.navigateTo({
        url: '/pages/index/teacher/index?type=4'
      })
    }
    if(type === 8){
      return uni.navigateTo({
        url: '/pages/index/teacher/index?type=3'
      })
    }
    uni.navigateTo({
      url: '/pages/index/practice/index?type=' + type
    })
  })
}
onShareAppMessage(() => {
  return {
    title: "低空科技-执照考题宝典",
    path: "/pages/index/index",
    imageUrl: utils.imgFormat('/profile/image/bg1.png')
  }
})
</script>

<style lang="scss" scoped>
.gride2 {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 22rpx;

  .gride2-item1 {
    background: linear-gradient(to bottom, #F27200  0%, #FEE381 100%);
  }

  .gride2-item2 {
    background: linear-gradient(to bottom, #0070FF  0%, #7FE5FF 100%);
  }
}

.top10 {
  top: -12rpx;
}
.bg1{
  height: 667rpx;
  background: linear-gradient( 180deg, #87ADFF 0%, #FFFFFF 100%);
  z-index: -1;
}
.line{
  height: 1rpx;
  background-color: rgba(230,230,230,0.6);
}
</style>